'use strict';

import Base from './base.js';

export default class extends Base {
  /**
   * index action
   * @return {Promise} []
   */
  async indexAction(){
    //auto render template file index_index.html
	this.meta_title = '美容院管理后台';
	//获取当前连锁机构下的店家信息
	let glist = await this.model('or_shop')
				.alias('os')
				.field('os.id,os.name,oi.phone,oi.address,oi.logo,count(*) as num ')
				.join("think_or_shopinfo oi ON os.id=oi.s_id")
				.join("think_or_shop_admin ou ON os.id=ou.s_id")
				.where({'os.o_id':this.userinfo.o_id})
				.group("os.id")
				.select();					
    return this.json(glist);
  }
  
  
	async getadmininfoAction(){
		let ainfo = await this.model('or_admin').where({id:this.userinfo.id}).find();
		return this.json(ainfo);
	}
  
	async getbroadcastAction(){
	    let uinfo = await this.model('or_admin').where({id:this.userinfo.id}).find();
	    let depar = await this.model('or_department').where({id: uinfo.departmentid}).find();
	    if (depar.floor <= 1) {
	      let gb = await this.model('or_broadcast').where({range:depar.floor}).find();
	      return this.json(gb);
	    } else {
	      return this.json({
	        isbroadcast : 2
	      });
	    }
	}
}